<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>

<![endif]-->
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/webuploader-0.1.5/webuploader.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加产品分类</title>

<!-- 加这个是解决选择图片按钮不可选的情况 ，其中百分之多少自己调吧-->
<style>
    #filePicker div:nth-child(2){width:10%!important;height:100%!important;}
</style>
</head>
<body>
<div class="page-container">
	<form action="<%=path%>/manager/rubbishTypeFir/rubbishTypeChangeUpLoad" method="post" class="form form-horizontal" id="f">
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				分类名称：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" placeholder="${requestScope.firsttypes.title}" name="title" id="title" class="input-text"  >
			</div>
		</div>
		
		<br/>
		<!-- <div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">缩略图：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="uploader-thum-container">
					<div id="fileList" class="uploader-list"></div>
					<div id="upInfo" ></div>
					<div id="filePicker">选择图片</div>
					<button id="btn" class="btn btn-default btn-uploadstar radius ml-10">开始上传</button>
				</div>
			</div>
		</div> -->
		
		<div class="row cl">
		<div id="uploader-demo">
            <!--用来存放item-->
            <label class="form-label col-xs-4 col-sm-2">缩略图：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="uploader-thum-container">
            <div id="fileList" class="uploader-list"></div>
            <div id="upInfo" ></div>
            <div id="filePicker" >选择图片</div>
        		</div>
        		<input type="button" id="btn" class="btn btn-default btn-uploadstar radius ml-10" value="开始上传">
        	</div>
        <input type="hidden" id="icon" name="icon">
        <input type="hidden" name="id" value="${param.id }">
		</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">描述：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<textarea name="content" cols="" rows="" class="textarea"  placeholder="${requestScope.firsttypes.content}" onKeyUp="$.Huitextarealength(this,100)"></textarea>
				
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input id="subBtn" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;发布&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="<%=path%>/static/managecss/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/My97DatePicker/4.8/WdatePicker.js"></script>

<script type="text/javascript" src="<%=path%>/static/webuploader-0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
$("#subBtn").click(function() {
	//检查标题
	var title = $("#title").val();
	if (title == "") {
		$("#titleMsg").html("标题必须输入");
		$("#title").focus();
		return;
	} else {
		$("#titleMsg").html("");
	} 
});	

jQuery(function() {
    var $ = jQuery,
        $list = $('#fileList'),
        // 优化retina
        ratio = window.devicePixelRatio || 1,
        // 缩略图大小
        thumbnailWidth = 100 * ratio,
        thumbnailHeight = 100 * ratio,
        // Web Uploader实例
        uploader;

        // 初始化Web Uploader
        uploader = WebUploader.create({
        // 自动上传。
        auto: false,
        // swf文件路径
        swf:'<%=path%>/static/webuploader-0.1.5/Uploader.swf',
        // 文件接收服务端。
        server: '<%=path%>/manage/firstTypeUpLoad',
        fileNumLimit:'1',  //文件总数量只能选择1个 

        // 选择文件的按钮。可选。
        pick: {
            id:'#filePicker',  //选择文件的按钮
            multiple:false, 
            label: '点击选择图片'
               },   
     // 图片质量，只有type为`image/jpeg`的时候才有效。
        quality: 90,

        //限制传输文件类型，accept可以不写 
        accept: {
            title: 'Images',//描述
            extensions: 'gif,jpg,jpeg,png',//类型
            mimeTypes: '.gif,.jpg,.jpeg,.png'//mime类型
        }
    });


 // 当有文件添加进来的时候，创建img显示缩略图使用
     uploader.on( 'fileQueued', function( file ) {
        var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                    '<img>' +
                    '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
            $img = $li.find('img');

        // $list为容器jQuery实例
        $list.empty();
        $list.append( $li );

        // 创建缩略图
        // 如果为非图片文件，可以不用调用此方法。
        // thumbnailWidth x thumbnailHeight 为 100 x 100
        uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }
            $img.attr( 'src', src );
        }, thumbnailWidth, thumbnailHeight );
    }); 

  // 文件上传过程中创建进度条实时显示。    uploadProgress事件：上传过程中触发，携带上传进度。 file文件对象 percentage传输进度 Nuber类型
    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');

        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
        }

        $percent.css( 'width', percentage * 100 + '%' );
    });

    // 文件上传成功时候触发，给item添加成功class, 用样式标记上传成功。 file：文件对象，response：服务器返回数据
    uploader.on( 'uploadSuccess', function( file,response) {
        $( '#'+file.id ).addClass('upload-state-done');
        //console.info(response);
      $("#upInfo").html("<font id='imgPath' color='red'>"+response._raw+"</font>");
      $("#icon").val(response._raw);
      alert("上传成功");

    });

    // 文件上传失败                                file:文件对象 ， code：出错代码
    uploader.on( 'uploadError', function(file,code) {
        var $li = $( '#'+file.id ),
            $error = $li.find('div.error');

        // 避免重复创建
        if ( !$error.length ) {
            $error = $('<div class="error"></div>').appendTo( $li );
        }

        $error.text('上传失败! ');
    });

    // 不管成功或者失败，文件上传完成时触发。 file： 文件对象
    uploader.on( 'uploadComplete', function( file ) {
        $( '#'+file.id ).find('.progress').remove();
    });

 // 所有文件上传成功后调用        
    uploader.on('uploadFinished', function () {
        //清空队列
         uploader.reset();
    });
  //只允许上传一个，每次文件加入队列前触发
    uploader.on('beforeFileQueued',function(){
        uploader.reset();
        uploader.refresh();
    });

    //绑定提交事件
    $("#btn").click(function() {
        console.log("上传...");
        uploader.upload();   //执行手动提交
      });
 
});


</script>
</body>
</html>